package com.goods.controller.business;

import com.goods.business.service.ProductStockService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductStockVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Api(tags = "业务模块-物资库存相关接口")
@RestController
@RequestMapping("/business/product")
public class ProductStockController {

    @Autowired
    private ProductStockService productStockService;

    //findAllStocks?pageSize=9&pageNum=1

    @ApiOperation(value = "物资库存分页展示")
    @GetMapping("/findProductStocks")
    public ResponseBean findProductStocks(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
            String categorys,String name, ProductStockVO productStockVO
    ) {
        PageVO<ProductStockVO> stockPageVO =
                productStockService.findProductStocks(pageNum, pageSize,categorys,name,productStockVO);
        return ResponseBean.success(stockPageVO);
    }

    //构建饼图对象  findProductStocks?pageSize=9&pageNum=1
    @ApiOperation(value = "物资库存展示")
    @GetMapping("/findAllStocks")
    public ResponseBean findAllStocks(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
            String categorys,String name, ProductStockVO productStockVO) {
        PageVO<ProductStockVO> allStockVOs =
                productStockService.findProductStocks(pageNum,pageSize,categorys,name,productStockVO);
        List<ProductStockVO> rows = allStockVOs.getRows();
        return ResponseBean.success(rows);
    }

}
